/// @tags: ShortestPath CartesianTree
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

namespace BlueQuantum {

typedef long long LL;

int const N = 1e5 + 5, T = 2.5e5 + 5;
LL const INF = 0x3f3f3f3f3f3f3f3f;

struct Node {
  int x;
  LL w;
  inline bool operator<(Node const& rhs) const { return w > rhs.w; }
};

priority_queue<Node> pq;

struct Edge {
  int v, w, next;
} e[T * 10];

int n, m, ecnt, ncnt;
int heads[N + T * 2], sta[N], w[N];
int stk[N], top, fa[N];
LL dis[N + T * 2];

inline void add(int u, int v, int w) {
  e[++ecnt] = (Edge){v, w, heads[u]}, heads[u] = ecnt;
}

inline void buildMax(int m) {
  fa[stk[top = 1] = 1] = 0;
  for (int i = 2; i <= m; ++i) {
    fa[i] = 0;
    if (w[sta[i]] > w[sta[stk[top]]]) {
      while (top && w[sta[i]] > w[sta[stk[top]]]) --top;
      fa[stk[top + 1]] = i;
    }
    fa[i] = stk[top];
    stk[++top] = i;
  }
  for (int i = 1; i <= m; ++i) {
    add(sta[i], ncnt + i, 0);
    add(ncnt + i, ncnt + i + m, w[sta[i]]);
    add(ncnt + i + m, sta[i], 0);
    if (fa[i]) {
      add(ncnt + i, ncnt + fa[i], 0);
      add(ncnt + fa[i] + m, ncnt + i + m, 0);
    }
  }
  ncnt += m * 2;
}

inline void buildMin(int m) {
  for (int i = 1; i <= m; ++i) {
    add(sta[i], ncnt + i, 0);
    add(ncnt + i, ncnt + i + m, w[sta[i]]);
    add(ncnt + i + m, sta[i], 0);
  }
  for (int i = 1; i < m; ++i) {
    add(ncnt + i, ncnt + i + 1, 0);
    add(ncnt + i + m, ncnt + i + m + 1, 0);
  }
  ncnt += m * 2;
}

inline void dij() {
  for (int i = 1; i <= ncnt; ++i) dis[i] = INF;
  pq.push((Node){n, dis[n] = 0});
  while (!pq.empty()) {
    int u = pq.top().x;
    LL d = pq.top().w;
    pq.pop();
    if (d != dis[u]) continue;
    for (int i = heads[u], v; i; i = e[i].next) {
      if (dis[u] + e[i].w < dis[v = e[i].v]) {
        dis[v] = dis[u] + e[i].w;
        pq.push((Node){v, dis[v]});
      }
    }
  }
}

inline int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> w[i];
  ncnt = n;
  for (int a, t, i = 1; i <= m; ++i) {
    cin >> a >> t;
    for (int i = 1; i <= t; ++i) cin >> sta[i];
    switch (a) {
      case 1:
        buildMax(t);
        break;
      case 2:
        buildMin(t);
        break;
    }
  }
  dij();
  LL ans = 0;
  for (int i = 1; i <= n; ++i) ans ^= dis[i];
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/sta/CodeTmp/testdata.in", "r", stdin);
  freopen("/sta/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("graph.in", "r", stdin);
  freopen("graph.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
